/**
 * 
 */
package com.wskj.library.user.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wskj.library.pojo.UserInfo;
import com.wskj.library.service.UserService;
import com.wskj.library.service.impl.UserServiceImpl;
import com.wskj.util.RequestUtil;
import com.wskj.util.StringUtil;

/**
 * @author 胡洋
 * @describe 
 * @Date 2018年3月22日下午6:09:59
 * @version 1.0
 */
@WebServlet(urlPatterns="/reader/update.do")
public class UpdateUserServlet extends HttpServlet {
	private  UserService userService=new UserServiceImpl();
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		 int id=StringUtil.nullToInt(req.getParameter("id"));		 
		 UserInfo user = userService.getUserById(id);		 
		 req.setAttribute("user", user);
		 req.getRequestDispatcher("/WEB-INF/page/reader/update.jsp").forward(req, resp);
	}
	
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		
		UserInfo user = RequestUtil.convertRequestToEntity(UserInfo.class, req);
		
		boolean result=userService.updateUserInfo(user);
		resp.sendRedirect(req.getContextPath()+"/reader/list.do");
	}
}
